﻿using B.Auth.APi.Application.Command.Role;
using B.Auth.Domain.Entity;
using B.Auth.Domain.Repository;
using B.Auth.Enum;
using MediatR;

namespace B.Auth.APi.Application.CommandHand.Role
{
    public class RouseUserShowCommandHand : IRequestHandler<RouseUserShowCommand, ApiResult<List<int>>>
    {
        private readonly IBaseRepository<RoleUser> db;

        public RouseUserShowCommandHand(IBaseRepository<RoleUser> db)
        {
            this.db = db;
        }

        public Task<ApiResult<List<int>>> Handle(RouseUserShowCommand request, CancellationToken cancellationToken)
        {

            var result=new ApiResult<List<int>>();
            List<int> list = db.GetAll().Where(x => x.RoleId == request.roleId).Select(x => x.UserId).ToList();
            result.data = list;
            return Task.FromResult(result);

        }
    }
}
